package com.wyh.mapper;

import com.wyh.entity.Account;

import com.wyh.entity.User_Name;
import com.wyh.utils.sqlUtils.user.updateUserSqlDynamic;
import com.wyh.utils.sqlUtils.user.addUserSqlDynamic;
import org.apache.ibatis.annotations.*;

import java.util.List;


@Mapper
public interface UserMapper {
    @Select("select * from user where name = #{text} ")
    Account findAccountByName(String text);

    @Select("select * from user where username = #{text} or email = #{text}")
    Account findAccountByNameOrEmail(String text);

    @Select("select * from user where uid=#{uid}")
    Account findAccount(int uid);

    @Select("select uid from user where Username=#{Username}")
    int findUidByUsername(String Username);

    @Select("select uid, user.Username from user")
    List<User_Name> findNameOfAccount();

    @Insert("INSERT INTO user (name, email, telephoneNumber, CN_ID, permission, gender, remark, Username, password) " +
            "VALUES (#{name}, #{email}, #{telephoneHNumber}, #{CN_ID}, #{permission}, #{gender}, #{remark}, #{username}, #{password})")
    void insertAccount(Account account);

    @Delete("DELETE FROM user WHERE email = #{email}")
    void deleteAccountByEmail(@Param("email") String email);

    @UpdateProvider(type = updateUserSqlDynamic.class , method = "updateDynamic")
    void updateAccount(Account account);

    @Select("select uid, name, email, telephoneNumber, CN_ID, house.address, permission, gender, user.remark,Username, password " +
            " from user left join communitymanagementsystem.user_house uh on user.uid = uh.user_id left join house on uh.house_id = house.house_id")
    List<Account> findAll();

    @InsertProvider(type = addUserSqlDynamic.class , method = "addDynamic")
    void addUser(Account account);

}

